<template>
  <div>
    <!-- 面包屑导航区 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片区域 -->
    <el-card>
      <el-row :gutter="10">
        <el-col :span="7">
          <!-- 搜索框 -->
          <el-input
            placeholder="请输入内容"
            clearable
            v-model="queryInfo.query"
            @clear="getOrdersList"
          >
            <el-button
              slot="append"
              icon="el-icon-search"
              @click="getGoodsList"
            ></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!-- 表格区域 -->
      <el-table :data="ordersList" style="width: 100%" border stripe>
        <el-table-column type="index"></el-table-column>
        <el-table-column
          label="订单编号"
          prop="order_number"
          width="800"
        ></el-table-column>
        <el-table-column
          label="订单价格"
          prop="order_price"
          width="100"
        ></el-table-column>
        <el-table-column label="是否付款" width="120">
          <template slot-scope="scope">
            <el-tag type="danger" v-if="scope.row.pay_status === 0"
              >未付款</el-tag
            >
            <el-tag type="success" v-else="scope.row.pay_status === 1"
              >已付款</el-tag
            >
          </template>
        </el-table-column>
        <el-table-column label="是否发货" width="60">
          <template slot-scope="scope">
            <span v-if="scope.row.is_send === '是'">是</span>
            <span v-else="scope.row.is_send === '否'">否</span>
          </template>
        </el-table-column>
        <el-table-column
          label="下单时间"
          prop="create_time"
          width="200"
        ></el-table-column>
        <el-table-column label="操作" width="200">
          <template slot-scope="scope">
            <el-button
              type="primary"
              size="mini"
              icon="el-icon-edit"
              @click="handleEditDialogVisible"
            ></el-button>
            <el-button
              type="success"
              size="mini"
              icon="el-icon-location-outline"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[10, 15, 20, 25]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
    <!-- 更改地址对话框 -->
    <el-dialog title="修改地址" :visible.sync="editDialogVisible" width="30%">
      <el-form
        :model="addressForm"
        :rules="addressFormRules"
        ref="addressFormRef"
        label-width="100px"
      >
        <el-form-item label="省市区/县" prop="address1">
          <el-cascader
            v-model="addressForm.address1"
            :options="cityData"
            style="width:100%"
          ></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="address2">
          <el-input v-model="addressForm.address2"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="editDialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import cityData from './citydata'
export default {
  data() {
    return {
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10,
      },
      ordersList: [],
      total: 1,
      editDialogVisible: false,
      addressForm: {
        address1: [],
        address2: '',
      },
      addressFormRules: {
        address1: [{ required: true, message: '请输入地址', trigger: 'blur' }],
        address2: [
          { required: true, message: '请输入详细地址', trigger: 'blur' },
        ],
      },
      cityData: cityData,
    }
  },
  created() {
    this.getOrdersList()
  },
  methods: {
    getGoodsList() {},
    async getOrdersList() {
      const { data: res } = await this.axios.get('orders', {
        params: this.queryInfo,
      })
      if (res.meta.status != 200) {
        return this.$message.error('获取订单列表失败')
      }
      res.data.goods.forEach((item) => {
        let time = new Date(item.create_time)
        item.create_time =
          time.getFullYear() +
          '-' +
          (time.getMonth() + 1) +
          '-' +
          time.getDate() +
          ' ' +
          time.getHours() +
          ':' +
          time.getMinutes() +
          ':' +
          time.getSeconds()
      })
      this.ordersList = res.data.goods
      this.total = res.data.total
      console.log(res)
    },
    handleSizeChange(currentSize) {
      this.queryInfo.pagesize = currentSize
      this.getOrdersList()
    },
    handleCurrentChange(currentPage) {
      this.queryInfo.pagenum = currentPage
      this.getOrdersList()
    },
    handleEditDialogVisible() {
      this.editDialogVisible = true
    },
  },
}
</script>

<style></style>
